"""Disk cache utilities"""

import tempfile
from os.path import join

from diskcache import Cache
from loguru import logger

temp_dir = tempfile.gettempdir()
cache_dir = join(temp_dir, "ios_cov_manager")
cache = Cache(directory=cache_dir)


class DiskCacheUtil:
    """Disck cache util"""

    @staticmethod
    def set(key: str, value: str):
        """Set a value in the cache"""
        with cache.transact():
            cache.set(key=key, value=value)

    @staticmethod
    def has(key: str):
        """Check if key exists"""

        return key in cache

    @staticmethod
    def get(key: str):
        """Get a value from the cache"""

        return cache.get(key=key)

    @staticmethod
    def delete(key: str):
        """Delete a key"""

        with cache.transact():
            value = cache.pop(key=key)
            logger.info(f"Deleted key: {key}, value: {value}")
